package pro.wyn.servlet;

import pro.wyn.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/wyn/adduser")
public class loginUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.取值
        String name = request.getParameter("n");
        String password = request.getParameter("p");
        //String id = request.getParameter("i");
        String sql="SELECT id FROM `user` where name=? and `password`=?";
        Integer id = JdbcUtils.select(sql,Integer.class,name,password);
        if(id !=null&&id>0){
            //重定向到首页
            response.sendRedirect("/wyn/index.jsp");
        } else {
            //重定向到用户登录页
            response.sendRedirect("/wyn/resume.jsp");
        }
    }
}
